<?php

namespace App\Http\Controllers\Api\gao;

use App\Utils\Service\MongoDB;
use Illuminate\Http\Request;

/**
 * 存储聊天记录
 */
class MassageController
{
    public function sendMsg(Request $request)
    {
        try {
            $params = $request->post();

            //调用mongo数据库
            $result = MongoDB::insertOne([
                'form' => $params['form_user'], //发送者
                'to' => $params['to_user'],     //接受者
                'content' => $params['content'] //发送的内容
            ]);
            if (!$result) throw new \Exception('未知错误，发送失败');
            return response(['code'=>0,'data'=>$result,'msg'=>'发送成功']);
        }catch (\Exception $exception)
        {
            return response(['code'=>0,'data'=>'','msg'=>$exception->getMessage()]);
        }
    }


}
